package com.lzw.breadknife.sample.mvvm.viewmodel;

import android.widget.Toast;

import com.lzw.breadknife.sample.bean.LoginResult;
import com.lzw.breadknife.sample.mvvm.LoginActivityUnbinder;
import com.lzw.breadknife.sample.mvvm.base.BaseViewModel;
import com.lzw.breadknife.sample.mvvm.model.ILoginModel;
import com.lzw.breadknife.sample.mvvm.model.LoginModel;
import com.lzw.breadknife.sample.mvvm.view.ILoginView;

/**
 * author  : AWeiLoveAndroid
 * e-mail  : lzw460433675@163.com
 * github  : https://gitee.com/AWeiLoveAndroid/BreadKnife
 * project : BreadKnife
 */
public class LoginViewModel extends BaseViewModel<ILoginView, ILoginModel, LoginActivityUnbinder> implements ILoginViewModel {

    public LoginViewModel(ILoginView view, LoginActivityUnbinder unBinder) {
        super(view, unBinder);
    }

    @Override
    protected ILoginModel createModel() {
        return new LoginModel(this);
    }

    @Override
    public void onLoginClick(String account, String pswd) {
        if (account.length() < 3) {
            Toast.makeText(context(), "账号不正确", Toast.LENGTH_SHORT).show();
            return;
        }
        if (pswd.length() < 3) {
            Toast.makeText(context(), "密码不正确", Toast.LENGTH_SHORT).show();
            return;
        }
        model.login(account, pswd);
    }

    @Override
    public void callbackLogin(LoginResult result) {
        unBinder.setResult(result);
    }
}
